export const Cart = {
  state: {
    stateAll: false,
    cartlist: [{
        shopstore: '哈哈家',
        shoplist: [
          // {
          //   id: 51,
          //   shop: "苏宁生鲜】 湾仔码头玉米蔬菜猪肉水饺720g 速冻饺子 方便速食",
          //   picture: "https://image2.suning.cn/uimg/b2c/newcatentries/0010128947-000000000602731511_1_800x800.jpg",
          //   product: "苏宁生鲜】 湾仔码头玉米蔬菜猪肉水饺720g 速冻饺子 方便速食",
          //   price: 28.67,
          //   oldprice: 78,
          //   putaway: 1,
          //   detail: null,
          //   categoryname: "甜点/面食",
          //   categoryId: 6,
          //   num: 1,
          //   state: false
          // }
        ],
        singlestate: false,
      },
      {
        shopstore: '晁然家',
        shoplist: [],
        singlestate: false,
      },
    ],


  },
  mutations: {
    SAVE_CARTLIST(state, value) {
      //定义店铺对象
      let arr = ['哈哈家', '晁然家']
      //随机选择一家
      let randNum = Math.floor(Math.random() * 10)<=4?0:1
      state.cartlist.forEach(item => {
        if (item.shopstore == arr[randNum]) {
          item.shoplist.push(value)
          console.log(item.shoplist);
        }
      });
    }
  },
  actions: {
    // saveCartlist({
    //   commit
    // }, value) {
    //   commit('SAVE_CARTLIST', value)
    // },
    saveCartlist(context, value) {
      context.commit('SAVE_CARTLIST', value)
    },

  }
}
